/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ch06;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class UserDAO {
    public boolean findByUserNameAndPassword(String username, String password) {
        Connection conn = null;
        PreparedStatement pstat = null;
        ResultSet rs = null;
        try {
            conn = DBConnection.getConnection();
            pstat = conn.prepareStatement("select * from user"
                    + " where username=?  and password=?");
            pstat.setString(1, username);
            pstat.setString(2, password);
            rs = pstat.executeQuery();
            if (rs.next()) {
                return true;
            } else {
                return false;
            }
        } catch (SQLException e) {
            System.out.println(e.getMessage());
            return false;

        }

    }
    
     public boolean findByUserNameAndPassword1(String username, String password) {
        Connection conn = null;
        PreparedStatement pstat = null;
        ResultSet rs = null;
        boolean flag=false;
        try {
            conn = DBConnection.getConnection();
            pstat = conn.prepareStatement("select * from user"
                    + " where username=?  and password=?");
            pstat.setString(1, username);
            pstat.setString(2, password);
            rs = pstat.executeQuery();
            if (rs.next()) {
                flag= true;
            } 
        } catch (SQLException e) {
            System.out.println(e.getMessage());
            

        }
        return flag;

    }
}
